package com.yxy.controller.admin;

import com.yxy.common.PageResult;
import com.yxy.common.Result;
import com.yxy.constant.RequestMapperConstant;
import com.yxy.domain.dto.UserPageQueryDTO;
import com.yxy.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminUserController")
@RequestMapping(RequestMapperConstant.ADMIN_REQUEST_MAPPER + "user")
@Slf4j
public class UserController {

    private final UserService userService;
    public UserController(UserService userService){
        this.userService = userService;
    }

    /**
     * 分页查询用户列表
     * @param userPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(UserPageQueryDTO userPageQueryDTO){
        log.info("分页查询用户列表：{}", userPageQueryDTO);
        PageResult page = userService.page(userPageQueryDTO);
        return Result.success("", page);
    }

    /**
     * 修改状态
     * @return
     */
    @PutMapping("/{id}/{status}")
    public Result status(@PathVariable int id, @PathVariable int status){
        log.info("修改状态：{}, {}", id, status);
        userService.state(id, status);
        return Result.success("");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestParam("ids") List<Integer> ids){
        log.info("根据id删除：{}", ids);
        userService.batchDelete(ids);
        return Result.success("删除成功");
    }
}
